/**
 * 文件级注释：
 * 前端通用类型与工具函数定义，包含接口响应包装类型、分页类型，
 * 以及与后端易票联进件相关的类型映射（Paper/Business 等）。
 * 统一规则：前端仅在返回值 code === 0 时认为接口调用成功。
 */

export interface ApiResult<T = any> {
  code: number
  message?: string | null
  data?: T
}

export interface PageRequest {
  pageIndex?: number
  pageSize?: number
}

export interface PageResult<T = any> {
  total: number
  data: T[]
}

// 统一前端成功判断：code === 0 为成功
export const isSuccess = (result?: ApiResult<any>): boolean => {
  return !!result && result.code === 0
}

/**
 * 类级注释：联系人信息（EpaylinksContactInfo）
 * 与后端 EpaylinksContactInfo 对齐，用于展示进件联系人信息。
 */
export interface EpaylinksContactInfo {
  /** 联系人姓名 */
  ContactPerson?: string
  /** 邮箱 */
  Email?: string
  /** 手机号 */
  ContactPhone?: string
  /** 联系人身份类型：0经办人，1法人 */
  ContactType?: string
  /** 证件类型 */
  ContactCertType?: string
  /** 证件号码 */
  ContactCertNo?: string
  /** 证件有效期起 */
  ContactCertFrom?: string
  /** 证件有效期止 */
  ContactCertTo?: string
  /** 证件照正面 fileId */
  ContactPhotoFront?: string
  /** 证件照正面 URL */
  ContactPhotoFrontURL?: string
  /** 证件照背面 fileId */
  ContactPhotoBack?: string
  /** 证件照背面 URL */
  ContactPhotoBackURL?: string
  /** 业务办理授权函 fileId */
  ContactBusinessAuth?: string
  /** 业务办理授权函 URL */
  ContactBusinessAuthURL?: string
}

/**
 * 类级注释：经营信息（EpaylinksCompanyInfo）
 * 与后端 EpaylinksCompanyInfo 对齐，用于展示进件经营资料与门店照片。
 */
export interface EpaylinksCompanyInfo {
  Province?: string
  City?: string
  Area?: string
  BusinessAddress?: string
  Mcc?: string
  StoreHeadPhoto?: string
  StoreHeadPhotoURL?: string
  StoreShopPhoto?: string
  StoreShopPhotoURL?: string
  StoreHallPhoto?: string
  StoreHallPhotoURL?: string
  StoreCashierPhoto?: string
  StoreCashierPhotoURL?: string
  OtherPhoto?: string[]
  OtherPhotoURL?: string[]
  ContractStatus?: string
  ContractAttachment?: string
  ContractAttachmentURL?: string
  Remarks?: string
  BusinessLicenseType?: string
  BusinessLicenseCode?: string
  BusinessLicenseName?: string
  BusinessLicensePhoto?: string
  BusinessLicensePhotoURL?: string
  BusinessLicenseFrom?: string
  BusinessLicenseTo?: string
  LawyerName?: string
  BusinessScope?: string
  RegisterAddress?: string
  RegisteredCapital?: number
}

/**
 * 类级注释：法人身份信息（EpaylinksLawyerInfo）
 */
export interface EpaylinksLawyerInfo {
  LawyerCertType?: string
  LawyerCertNo?: string
  LawyerCertPhotoFront?: string
  LawyerCertPhotoFrontURL?: string
  LawyerCertPhotoBack?: string
  LawyerCertPhotoBackURL?: string
  CertificateName?: string
  CertificateFrom?: string
  CertificateTo?: string
  LegalPersonPhone?: string
  LawyerCountry?: string
  LawyerAddress?: string
}

/**
 * 类级注释：注册账户信息（EpaylinksOpenAccountInfo）
 */
export interface EpaylinksOpenAccountInfo {
  OpenAccountType?: string
  LicenceAccount?: string
  LicenceAccountNo?: string
  LicenceOpenBank?: string
  LicenceOpenSubBank?: string
  OpeningLicenseAccountPhoto?: string
  OpeningLicenseAccountPhotoURL?: string
}

/**
 * 类级注释：结算账户信息（EpaylinksSettlementAccountInfo）
 */
export interface EpaylinksSettlementAccountInfo {
  SettleTarget?: string
  SettleAccountType?: string
  SettleAccountNo?: string
  SettleAccount?: string
  OpenBank?: string
  OpenSubBank?: string
  OpenBankCode?: string
  SettleCertFrontPhoto?: string
  SettleCertFrontPhotoURL?: string
  SettleCertBackPhoto?: string
  SettleCertBackPhotoURL?: string
  BankCardPhotoFront?: string
  BankCardPhotoFrontURL?: string
  BankCardPhotoBack?: string
  BankCardPhotoBackURL?: string
  OpenBankReservePhone?: string
  Postscript?: string
  Summary?: string
  Purpose?: string
  AccountIntentPhoto?: string
  AccountIntentPhotoURL?: string
  WithdrawProofPhoto?: string
  WithdrawProofPhotoURL?: string
  TransferApplyAttachment?: string
  TransferApplyAttachmentURL?: string
  SettleAttachment?: string
  SettleAttachmentURL?: string
  SettleLicensePhoto?: string
  SettleLicensePhotoURL?: string
  IsDefault?: string
}

/**
 * 类级注释：受益人信息（EpaylinksControllerInfo）
 */
export interface EpaylinksControllerInfo {
  ControllerName?: string
  ControllerType?: string
  ControllerNo?: string
  ControllerFrom?: string
  ControllerTo?: string
  ControllerCountry?: string
  ControllerAddress?: string
  ControllerPhotoFront?: string
  ControllerPhotoFrontURL?: string
  ControllerPhotoBack?: string
  ControllerPhotoBackURL?: string
}

/**
 * 类级注释：其他信息（EpaylinksOtherInfo）
 */
export interface EpaylinksOtherInfo {
  WechatChannelId?: string
  WechatBusinessId?: string
  AlipayChannelId?: string
  AlipayMcc?: string
  WechatMerchantName?: string
  AlipayMerchantName?: string
  AcqMatchName?: string
  UnionShortName?: string
  ServiceTel?: string
  IcpRecordNo?: string
  SiteUrl?: string
  WebsiteOrAppName?: string
  WxMiniAppName?: string
  WxPublicAccountName?: string
  WxMiniAppAuthPage?: string
  WxMiniAppHomePage?: string
  WxMiniAppOrderPage?: string
  WxPublicAccountAuthPage?: string
  WxPublicAccountHomePage?: string
  WxPublicAccountOrderPage?: string
  IcpRecordPhoto?: string
  WebsiteHomePage?: string
  WebsiteAfterSales?: string
  WebsiteOthers?: string
  ScenarioPhoto?: string[]
  PayFlowchart?: string[]
  PayFlowchartAttachment?: string
  SpecialPermit?: string[]
  WithdrawAgreement?: string
  AppStorePage?: string
  AppDescVideo?: string
  OtherSheetAttachment?: string
  HandheldPhotoForAccount?: string[]
  HandheldVideoForAccount?: string
}

/**
 * 类级注释：商户详细信息（EpaylinksPaper）
 */
export interface EpaylinksPaper {
  ShortName?: string
  MerchantType?: string
  SoleInvestor?: number
  ContactInfo?: EpaylinksContactInfo
  CompanyInfo?: EpaylinksCompanyInfo
  LawyerInfo?: EpaylinksLawyerInfo
  OpenAccountInfo?: EpaylinksOpenAccountInfo
  SettleAccountInfo?: EpaylinksSettlementAccountInfo
  ControllerList?: EpaylinksControllerInfo[]
  OtherInfo?: EpaylinksOtherInfo
}

/**
 * 类级注释：费率阶段（Stage）
 */
export interface Stage {
  FeeRate?: string
  FeePer?: number
  AmountFrom?: number
}

/**
 * 类级注释：银行计价费率阶段（BankStage）
 */
export interface BankStage {
  Bankcode: string
  FeeRate?: string
  FeePer?: number
}

/**
 * 类级注释：业务开通信息（EpaylinksBusinessInfo）
 */
export interface EpaylinksBusinessInfo {
  BusinessCode: string
  BusinessName?: string
  State?: string
  Msg?: string
  Stage?: Stage[]
  BankStage?: BankStage[]
  FeeMin?: number
  FeeMax?: number
  RefundEnabled?: string
  RefundFeeRate?: string
  RefundFeePer?: number
  CreditcardsEnabled?: string
  MaxTxsAmount?: number
  MinTxsAmount?: number
  SettleCycle: string
  SplitOriTradeFee?: string
  HolidayType?: string
  HolidayRate?: string
  HolidayPer?: number
  TaxFeeType?: string
  TaxFeePer?: number
  TaxFeeRate?: string
  ChannelFeeType?: string
  ChannelFeePer?: number
  ChannelFeeRate?: string
}
